package cn.edu.zju.om.nlp;

import java.util.ArrayList;
import java.util.List;

import edu.stanford.nlp.ling.Sentence;
import edu.stanford.nlp.ling.Word;
import edu.stanford.nlp.tagger.maxent.MaxentTagger;

public class SUPosTaggerAdapter implements PosTagger {
	
	private static MaxentTagger taggerInstance;
	
	public SUPosTaggerAdapter() throws Exception {
		if (taggerInstance == null) {
			taggerInstance = new MaxentTagger("models\\chinese.tagger");
		}
	}

	public List<TaggedWord> tagWordList(List<String> wordsToTag) {
		
		List<Word> wordList = new ArrayList<Word>();
		for(String word : wordsToTag) {
			wordList.add(new Word(word));
		}
		
		Sentence<edu.stanford.nlp.ling.TaggedWord> tagResult =
			MaxentTagger.tagSentence(wordList);
		
		List<TaggedWord> ret = new ArrayList<TaggedWord>();
		for(edu.stanford.nlp.ling.TaggedWord taggedWord : tagResult) {
			ret.add(new SUTaggedWordAdapter(taggedWord));
		}
		
		return ret;
	}

}
